package com.le.tester.onjava8.l1_6;

import java.util.Random;

/**
 * createTime：2022/10/24 14:00
 * description：随机选择一个enum
 */
public class Enums {
    private static Random rand = new Random(47);

    //随机选取一个enum
    public static <T extends Enum<T>> T random(Class<T> ec) {
        return random(ec.getEnumConstants());
    }

    public static <T> T random(T[] values) {
        return values[rand.nextInt(values.length)];
    }
}
